from rest_framework.fields import SerializerMethodField
from rest_framework.serializers import ModelSerializer

from course.models import Teacher, Course


class TeacherSer(ModelSerializer):
    class Meta:
        model = Teacher
        fields = '__all__'


class CourseSer(ModelSerializer):
    tea = SerializerMethodField(read_only=True)

    def get_tea(self, obj):
        return {
            'name': obj.teacher.name,
            'id': obj.teacher.id,
            'job': obj.teacher.job,
            'intro': obj.teacher.intro,
            'headimg': obj.teacher.headimg
        }

    class Meta:
        model = Course
        fields = '__all__'
